
import 'dart:ui';

import 'package:elevator/model/base_model.dart';
import 'package:elevator/model/pum_info.dart';
import 'package:elevator/model/pus_info.dart';
import 'package:elevator/model/tcp_info.dart';
import 'package:elevator/model/warn_info.dart';
import 'package:flutter/material.dart';

///警报信息
class AlermInfo extends BaseModel{
  ///序号 0~31,EP PUS PUW 为-1
  int number = -1;
  ///对应id
  int id;
  ///对应SName
  String sName;
  ///对应LName_EN
  String lNameEn;
  ///对应LName_CN
  String lNameCn;
  ///对应color
  int color;
  ///对应push
  int push;
  ///类型 alerm 0，tpc 1，pus 2，3 pum
  int type = 0;

  AlermInfo( this.id,this.number, this.sName, this.lNameEn, this.lNameCn,
      this.color, this.push, this.type);

  static AlermInfo buildFormWarnInfo(WarnInfo warnInfo){
    return AlermInfo(warnInfo.id,warnInfo.number,warnInfo.sName,warnInfo.lNameEn,warnInfo.lNameCn,
      warnInfo.color,warnInfo.push,0);
  }

  static AlermInfo buildFormTpcInfo(TpcInfo tpcInfo){
    return AlermInfo(tpcInfo.id,tpcInfo.tpcAddr,tpcInfo.tpcSName,tpcInfo.tpcLName,tpcInfo.tpcLName,
        tpcInfo.tpcColor,tpcInfo.tpcPush,1);
  }

  static AlermInfo buildFormPusInfo(PusInfo pusInfo) {
    return AlermInfo(pusInfo.id,pusInfo.pusValue,pusInfo.pusSName,pusInfo.pusLName,pusInfo.pusLName,
        pusInfo.pusColor,pusInfo.pusPush,2);
  }

  static AlermInfo buildFormPumInfo(PumInfo pumInfo) {
    return AlermInfo(pumInfo.id,pumInfo.pumValue,pumInfo.pumSName,pumInfo.pumLName,pumInfo.pumLName,
        pumInfo.pumColor,pumInfo.pumPush,3);
  }

  @override
  String toString() {
    return 'AlermInfo{number: $number, id: $id, sName: $sName, lNameEn: $lNameEn, lNameCn: $lNameCn, color: $color, push: $push, type: $type}';
  }

  @override
  String getTag() {
    return sName;
  }

  Color getBgColor(){
    Color bgColor = Colors.white;
    if(color == 1){
      bgColor = Colors.red;
    }else if(color == 2){
      bgColor = Colors.yellow;
    }else if(color == 3){
      bgColor = Colors.green;
    }
    return bgColor;
  }

  compareTo(AlermInfo b) {
    if(b.color == 0){
      return 1;
    }else if(color == 0){
      return -1;
    }else{
      return color.compareTo(b.color);
    }
  }
}